(function(){
  
  var sps = window.ShortcutPathStorage = {
    getPaths: function() {
      var paths = localStorage.getItem('shortcut_paths') || '[]';
      return JSON.parse(paths);
    },

    getPath: function(path) {
      var paths = sps.getPaths();
      var length = paths.length;
      for (var i = 0; i < length; i++) {
        var _path = paths[i];
        if (_path[0] == path || _path[1] == path)
          return _path;
      }
      return null;
    },
    
    addPath: function(pathText, pathValue) {
      pathValue = pathValue || pathText;
      var paths = sps.getPaths();
      if (paths.length > 8) {
        paths.splice(3, 1);
      }
      paths.push([pathText, pathValue]);
      localStorage.setItem('shortcut_paths', JSON.stringify(paths));
    },

    setDefaultPath: function(path) {
      localStorage.setItem('default_shortcut_path', path);
    },

    getDefaultPath: function() {
      var defaultPath = localStorage.getItem('default_shortcut_path');
      return sps.getPath(defaultPath);
    }
  };
})();